package ibm.cognos.imt.template

import ibm.cognos.imt.DataItem
import groovy.xml.MarkupBuilder

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/12/14
 * Time: 11:14 AM
 * To change this template use File | Settings | File Templates.
 */
class DataItemTemplate extends AbstractTemplate{
    DataItem dataItem

    DataItemTemplate(item) {
        dataItem = item
    }

    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.dataItem(aggregate: "$dataItem.aggregate", name: "$dataItem.name") {
            expression(dataItem.exp)
            XMLAttributes {
                XMLAttribute(output: "no", name: "RS_dataType", value: "$dataItem.dataType")
                XMLAttribute(output: "no", name: "RS_dataUsage", value: "$dataItem.dataUsage")
            }

        }
    }

    @Override
    def getTemplateNode(closure=null) {
        root = new XmlSlurper().parseText(getSpecStr())
//        closure.delegate = root
//        closure.call()
        root
    }
}
